<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Project;
use App\Att;
class CheckController extends Controller
{
    //取出所有项目,供管理员审核
    public function prolist(){
      $pros = Project::orderBy('pid','desc')->get();
      return view('prolist',['pros'=>$pros]);
    }

    //审核项目,主要是修改projects ,和atts表
    public function check(Request $req,$pid){
      $pro = Project::find($pid);//find根据主键查
      $att = Att::where('pid',$pid)->first();//查询单行数据

      if(empty($pro)){
        return redirect('/prolist');
      }
      //把主表和附表的数据传过去
      return view('shenhe',['pro'=>$pro , 'att'=>$att]);
    }

    public function checkpost(Request $req,$pid){
      $pro = Project::find($pid);//find根据主键查
      $att = Att::where('pid',$pid)->first();//查询单行数
      if(empty($pro)){
        return redirect('/prolist');
      }
      $pro->title = $req->title;
      $pro->hrange = $req->hrange;
      $pro->rate = $req->rate;//百分比
      $pro->status = $req->status;

      $att->realname = $req->realname;
      $att->age = $req->age;
      $att->gender = $req->gender;
      $att->salary = $req->salary;
      $att->jobcity = $req->jobcity;
      $att->udesc = $req->udesc;

      if($pro->save() && $att->save()){
        return redirect('/prolist');
      }else{
        return 'error';
      }

    }
}
